package com.wd.health.view.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wd.health.R;
import com.wd.health.app.App;
import com.wd.health.model.adapter.ZixunAdapter;
import com.wd.health.model.bean.ZixunBean;
import com.wd.health.utils.RetrofitManager;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ZxgdActivity extends AppCompatActivity {

    private TextView tv;
    private ImageView img;
    private RecyclerView rv;
    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zxgd);
        initView();
        initData();
    }

    private void initData() {
        RetrofitManager.getInstance().getZixunData(id, 1, 15, new Observer<ZixunBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(ZixunBean zixunBean) {
                List<ZixunBean.ResultBean> list = zixunBean.getResult();
                ZixunAdapter zixunAdapter = new ZixunAdapter(App.getAppContext(), list);
                rv.setAdapter(zixunAdapter);
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    private void initView() {
        tv = findViewById(R.id.tv_zxgq_title);
        img = findViewById(R.id.img_back);
        rv = findViewById(R.id.rv_zxgd);
        rv.setLayoutManager(new LinearLayoutManager(this));
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        id = intent.getIntExtra("id", 0);
        tv.setText(name);
    }
}